from fastapi import APIRouter, Depends, Request
from sqlalchemy.ext.asyncio import AsyncSession
from config.get_db import get_db
from module_admin.aspect.data_scope import GetDataScope
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.entity.vo.business_vo import BusinessPageQueryModel
from module_admin.entity.vo.machine_vo import MachineModel
from module_admin.service.business_service import BusinessService
from module_admin.service.machine_service import MachineService
from module_admin.service.login_service import LoginService
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil
from utils.log_util import logger

businessController = APIRouter(prefix='/game/business', dependencies=[Depends(LoginService.get_current_user)])

@businessController.get(
    '/list', response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('game:business:list'))]
)
async def get_game_business_list(
    request: Request,
    page_query: BusinessPageQueryModel = Depends(BusinessPageQueryModel.as_query),
    query_db: AsyncSession = Depends(get_db),
    data_scope_sql: str = Depends(GetDataScope('BaBusiness')),
):
    logger.info(f'page_query: {page_query}')
    page_query_result = await BusinessService.get_list_services(
        query_db, page_query, data_scope_sql, is_page=True
    )

    return ResponseUtil.success(model_content=page_query_result)

@businessController.get('/machineSelect', dependencies=[Depends(CheckUserInterfaceAuth('game:business:list'))])
async def get_machine_select(
    request: Request, query_db: AsyncSession = Depends(get_db), data_scope_sql: str = Depends(GetDataScope('BaMachine'))
):
    search_list_query_result = await MachineService.get_machine_select_services(query_db, MachineModel(**{}), data_scope_sql)

    return ResponseUtil.success(data=search_list_query_result)